package com.sven.recorderandplayer;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import com.sven.player.SmallVoicePlayer;
import com.sven.player.VoicePlayer;
import com.sven.player.VoiceRecorder;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {


    @Bind(R.id.layout_record)
    FrameLayout layoutRecord;
    @Bind(R.id.activity_main)
    LinearLayout activityMain;
    @Bind(R.id.player)
    VoicePlayer player;
    @Bind(R.id.smallVoicePlayer)
    SmallVoicePlayer smallVoicePlayer;
    @Bind(R.id.player2)
    VoicePlayer player2;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        /*播放器*/
        player = (VoicePlayer) findViewById(R.id.player);
        player2 = (VoicePlayer) findViewById(R.id.player2);
        smallVoicePlayer = (SmallVoicePlayer) findViewById(R.id.smallVoicePlayer);
        smallVoicePlayer.setmGender(true);

        /*录音*/
        VoiceRecorder recorder = new VoiceRecorder();
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.layout_record, recorder, "VoiceRecorder")
                .commitAllowingStateLoss();
        recorder.setOnRecordSuccessListenter((path, ms) -> {
            player.play(path, ms);
//            player2.play(path, ms);
//            smallVoicePlayer.play(path, ms);
        });
    }
}
